#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>


int main(int argc, char **argv)
{
	pid_t		pid;


	printf("Parent process PID[%d] start running...\n", getpid());	//getpid()获取父进程自身的ID


	pid = fork();
	if(pid < 0)
	{
		printf("fork() create child process failure: %s\n", strerror(errno));
		return -1;
	}
	else if(pid == 0)	//子进程执行
	{
		printf("Child process PID[%d] start running, my parent PID is [%d]\n", getpid(),getppid());
		return 0;
	
	}
	else	//pid>0，父进程执行,返回子进程PID（pid）
	{
		printf("Parent process PID[%d] continue running, and child process PID is [%d]\n", getpid(), pid);
		wait(NULL);		//等待任意一个子进程结束
	}
	return 0;
}
